#ifndef __STICKS_H_
#include "usr_def.h"

#define RC_STICK_MID_CAL_SAMPLE_COUNT 100
#define STICK_APPLY_RANGE(x,min,max) ((x)>0?(x)*512L/(max):(x)*512L/-(min))
#define STICK_MAX(x,max) ((x)>(max)?(x):(max))
#define STICK_MIN(x,min) ((x)<(min)?(x):(min))

enum {
    RC_STICK_MID_CAL_ON_FLAG = 1 << 0,
    RC_STICK_MIN_CAL_ON_FLAG = 1 << 1,
    RC_STICK_MAX_CAL_ON_FLAG = 1 << 2,
    RC_STICK_BUTTON_CAL_ON_FLAG = 1 << 3,
};

struct stick_channel {
    int16_t value;
    int16_t max;
    int16_t min;
    int16_t adc;
    int16_t deadBand;
    int16_t preValue;
    int16_t lpf;
    int16_t caliMin;
    int16_t caliMax;
    uint32_t mid;
    uint8_t sum_cnt;
};
typedef struct rc_sticks {
    struct stick_channel rlr;
    struct stick_channel rud;
    struct stick_channel llr;
    struct stick_channel lud;
    int16_t sample_count;
    int16_t state;
    uint8_t idleCnt;
}rc_sticks_t;
void sticks_update(rc_sticks_t* s, uint16_t rlr, uint16_t rud, uint16_t llr, uint16_t lud);
// void sticks_set_deadBand(rc_sticks_t* s, uint16_t deadBand);
// void sticks_calibrate_mid(rc_sticks_t* s);
// void stick_range_calibrate(rc_sticks_t* s);
// void stick_range_cal_on(rc_sticks_t* s);
// void stick_range_cal_off(rc_sticks_t* s);
void stick_cali_on();
void stick_cali_off();

extern xdata rc_sticks_t rcSticks;
#endif // !__STICKS_H_